class_name DeathScreen
extends MarginContainer


signal timeout


@onready var countdownLabel: Label = $Border/MarginContainer/Contents/VBoxContainer/CountdownLabel
@onready var timer: Timer = $Timer

## 倒计时起始秒数
@export var countdown_start: int = 10


var _countdown: int


func _ready():
	_countdown = countdown_start
	timer.timeout.connect(on_timeount)
	timer.start()
	refresh()


func on_timeount():
	_countdown = clampi(_countdown - 1, 0, countdown_start)
	if _countdown < 1:
		timer.stop()
		timeout.emit()
		return
	refresh()


func refresh():
	countdownLabel.text = str(_countdown)
